000100* FUNCTION : CBU-options
000200* FILE : CBUP0003[.CBL]
000300 IDENTIFICATION DIVISION.
000400 PROGRAM-ID. CBUP0003.
000500 ENVIRONMENT DIVISION.
000600 INPUT-OUTPUT SECTION.
000700 FILE-CONTROL.
000800* <MVS>
000900*      SELECT iniFile ASSIGN TO UT-S-CBUINIT.
      * </MVS>
001000* <WIN>
001100    SELECT INIFILE ASSIGN TO "CBUNIT.INI"
001200     ORGANIZATION IS LINE SEQUENTIAL.
      * </WIN>
001300 DATA DIVISION.
001400 FILE SECTION.
001500 FD  INIFILE BLOCK 0.
001600 01  INIrecord       PIC X(80).
001700
001800 WORKING-STORAGE SECTION.
001900
002000      COPY CBUC00W6.
002100      COPY CBUC0004.
002200* PROGRAM VARIABLES
002300
002400 01  FILLER                      PIC X(3)       VALUE "YES".
002500     88 CBU-1ST-RUN                             VALUE "YES".
002600     88 CBU-FURTHER-RUN                         VALUE "NO".
002700
002800 01  INPUT-FILE-STATUS           PIC X          VALUE SPACE.
002900     88 INI-NOT-OPEN                            VALUE SPACE.
003000     88 INI-OPEN                                VALUE "O".
003100     88 INI-END                                 VALUE "E".
003200
003300 01  RES-KEYWORD                 PIC X(20).
003400 01  RES-KEYVALUE                PIC X(60).
003500
003600 01  INI-IND1                    PIC S9(4) COMP VALUE 0.
003700 01  INI-IND2                    PIC S9(4) COMP VALUE 0.
003800 01  INI-IND3                    PIC S9(4) COMP VALUE 0.
003900 01  INI-NB                      PIC S9(4) COMP VALUE 0.
004000 01  INI-DATA.
004100     05 INI-LINE                 OCCURS 20.
004200        10 INI-TYPE              PIC X.
004300        10 INI-VALUE.
004400           15 INI-KEYWORD        PIC X(20).
004500           15 INI-KEYVALUE       PIC X(60).
004600
004700
004800 LINKAGE SECTION.
004900     COPY CBUC0000.
005000 PROCEDURE DIVISION USING CBU-ctx.
005100
005200 mainline.
005300
005400* 1st STEP : the batch command file is read, checked and stored
005500* in an array
005600     PERFORM DEFAULT-OPTIONS.
005700     PERFORM INI-READ.
005800     PERFORM UNTIL INI-END
005900        PERFORM INI-PROCESS
006000        PERFORM INI-READ
006100     END-PERFORM.
006200
006300     PERFORM VARYING INI-IND1 FROM 1 BY 1 UNTIL INI-IND1 > INI-NB
006400        IF INI-TYPE (INI-IND1) = "*"
006500           THEN CONTINUE
006600           ELSE PERFORM PROCESS-KEYWORD
006610        END-IF
006700     END-PERFORM.
006800
006900     GOBACK.
007000
007100 INI-READ.
007200     IF INI-NOT-OPEN THEN
007300         OPEN INPUT INIFILE
007400         SET INI-OPEN TO TRUE
007500     END-IF.
007600
007700*    READ INIFILE NEXT RECORD INTO INIrecord
007710     READ INIFILE
007800        AT END
007900           CLOSE INIFILE
008000           SET INI-END TO TRUE.
008100
008200 INI-PROCESS.
008300
008400     MOVE INIrecord to STRING-TO-STRIP
008500     PERFORM STRIP-A-STRING
008600     IF STRIP-LENGTH = 1 AND STS (STRIP-BEG) = SPACE
008700        CONTINUE
008800        ELSE
008900        MOVE STRING-TO-STRIP (STRIP-BEG : STRIP-LENGTH)
009000        TO STRING-TO-STRIP
009100        IF STS (1) = "*"
009200           ADD 1 TO INI-NB
009300           MOVE STRING-TO-STRIP TO INI-LINE (INI-NB)
009400        ELSE
009500           IF STS (1) = "<"
009600              PERFORM VARYING INI-IND1 FROM 1 BY 1
009700              UNTIL INI-IND1 > STRIP-LENGTH
009800              OR STS (INI-IND1) = ">"
009900                 CONTINUE
010000              END-PERFORM
010100              IF STS (INI-IND1) = ">"
010200                 ADD 1 TO INI-NB
010300                 MOVE "K" TO INI-TYPE (INI-NB)
010400                 MOVE STRING-TO-STRIP (1 : INI-IND1)
010500                 TO INI-KEYWORD (INI-NB)
010600                 ADD 1 TO INI-IND1 GIVING INI-IND2
010700                 COMPUTE INI-IND3 = STRIP-LENGTH - INI-IND1
010800                 MOVE STRING-TO-STRIP (INI-IND2 : INI-IND3)
010900                 TO STRING-TO-STRIP
011000                 PERFORM STRIP-A-STRING
011100                 MOVE STRING-TO-STRIP (STRIP-BEG : STRIP-LENGTH)
011200                 TO INI-KEYVALUE (INI-NB)
011300              ELSE
011400                 PERFORM UNDEFINED-INI-LINE
011500              END-IF
011600           ELSE
011700              PERFORM UNDEFINED-INI-LINE
011800           END-IF
011900        END-IF
012000     END-IF.
012100
012200 PROCESS-KEYWORD.
012300
012400     MOVE INI-KEYWORD (INI-IND1) TO RES-KEYWORD
012500     MOVE INI-KEYVALUE (INI-IND1) TO RES-KEYVALUE
012600     EVALUATE TRUE
012700
012800        WHEN RES-KEYWORD = "<LOGLEVEL>"
012900           AND RES-KEYVALUE = "VERBOSE"
013000             SET VERBOSE-MODE TO TRUE
013100        WHEN RES-KEYWORD = "<LOGLEVEL>"
013200           AND RES-KEYVALUE = "DEBUG"
013300             SET DEBUGGING-MODE TO TRUE
013400        WHEN RES-KEYWORD = "<LANGUAGE>"
013500           MOVE RES-KEYVALUE TO CBU-LANGUAGE
013600
013700* ERROR
013800        WHEN OTHER
013900           PERFORM INVALID-KEYWORD
014000     END-EVALUATE.
014100
014200 DEFAULT-OPTIONS.
014300
014400     SET STANDARD-LOG TO TRUE.
014500
014600 INVALID-KEYWORD.
014700
014800     DISPLAY "EN109 INVALID KEYWORD" RES-KEYWORD RES-KEYVALUE.
014900
015000 UNDEFINED-INI-LINE.
015100
015200     DISPLAY "EN110 UNDEFINED INI LINE : " INIrecord .
015300
015400 CALLPRINT.
015500
015600* PRINT CURRENT LINE
015700     MOVE CBU-LANGUAGE TO CBU-MSG-LG
015800     CALL CBU-log-print USING CBU-LOG-PRINT-INTERFACE
015900* RESET DEFAULTS
016000     SET CBU-PRINT-A-LINE TO TRUE
016100     SET CBU-PRINT-ON-NEXT-LINE TO TRUE
016200     INITIALIZE CBU-MESSAGE-TO-PRINT.
016300
016400
016500* COPYBOOK OF STRING MANIPULATION ROUTINES
016600     COPY CBUC00P6.
